package com.xdxc.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xdxc.model.dto.CorrectAnswerDTO;
import com.xdxc.model.entity.CorrectAnswer;
import com.xdxc.response.Result;
import com.xdxc.service.CorrectAnswerService;
import com.xdxc.service.QuestionService;
import com.xdxc.service.impl.QuestionsService;
import com.xdxc.vo.QuestionWithOptionsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/correctAnswer")
public class CorrectAnswerController {

    @Autowired
    private CorrectAnswerService correctAnswerService;

    @PostMapping("/getCorrectAnswer")
    public Result<CorrectAnswerDTO> getCorrectAnswer(@RequestParam long questionId){
        CorrectAnswer correctAnswer = correctAnswerService.getOne(new LambdaQueryWrapper<CorrectAnswer>().eq(CorrectAnswer::getQuestionId,questionId));
        return Result.success(new CorrectAnswerDTO().builder()
                .answerVersion(correctAnswer.getAnswerVersion())
                .judgmentAnswer(correctAnswer.getJudgmentAnswer())
                .optionIds(correctAnswer.getOptionIds())
                .fillKeywords(correctAnswer.getFillKeywords())
                .questionId(correctAnswer.getQuestionId())
                .build());
    }
}
